package prepro;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import myLucene.GetTime;
import myLucene.Props;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

public class VerbsPlusDF {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"/local/joofeit/dup")));
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File(
				"/local/joofeit/VerbsPlusDf")));
		String line = "";
		long start = System.currentTimeMillis();
		Directory iDirectory = FSDirectory.open(new File(Props.readIndexPath));
		IndexSearcher searcher = new IndexSearcher(iDirectory, true);
		IndexReader iReader = searcher.getIndexReader();
		System.out.println("Time needed: "
				+ GetTime.getDuration(start, System.currentTimeMillis()));
		while ((line = br.readLine()) != null) {
			bw.write(iReader.docFreq(new Term("index", line.split(" ")[1])) + " "
					+ line + "\n");
		}
		br.close();
		bw.close();
	}

}
